import express = require('express');
import path = require('path');
import platform = require('./public/platform/common/baseCommon');
import appServer = require('./public/platform/server/appServer');

// import appConfig = require('./public/project/test/config/server/appConfig');
import appConfig = require('./public/project/dataAnalysis/gsDataAnalysis/config/server/appConfig');


let app = express();

// 环境变量
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(app.router);

// 过滤服务文件夹,不能通过get请求访问
app.use(function (req, res, next) {
    let server = /(\/server\/)/g;//设置指定文件目录
    if (server.test(req.path)) {
        // 设置utf - 8编码格式
        res.writeHead(200, { 'Content-Type': 'text/html;charset=utf-8' });
        res.end("请求非法目录文件");
    } else {
        next();
    }
});

// 静态目录设定
app.use(express.static(path.join(__dirname, 'public')));

let configFilePath = path.join(__dirname, 'appConfig.json');

// 准备服务应用
let serverApp = <appServer.serverApplication>appServer.prepareConfig(appConfig.app, configFilePath, false, true);
// 启动应用
appServer.startServer(app, serverApp, () => {
    // 启动服务前执行
});
